﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace dkGameTool
{
    public partial class chooseChallenge : UserControl
    {
        private string DeviceId;
        public chooseChallenge(string deviceId)
        {
            InitializeComponent();

            this.DeviceId = deviceId;

            DataBaseManager dbHelper = DataBaseManager.GetInstance;

            this.dataGridView1.DataSource = dbHelper.getDataChallenge("");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataBaseManager.GetInstance.DelChallengeAllRecord(this.DeviceId);

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                DataGridViewCell celljd = row.Cells["chkjd"];
                Boolean bjd = false;
                if (celljd != null && celljd.Value != null)
                {
                    bjd = celljd.Value.ToString() == "True";

                }

                DataGridViewCell cellzd = row.Cells["chkzd"];
                Boolean bzd = false;
                if (cellzd != null && cellzd.Value != null)
                {
                    bzd = cellzd.Value.ToString() == "True";

                }

                DataGridViewCell cellkn = row.Cells["chkkn"];
                Boolean bkn = false;
                if (cellkn != null && cellkn.Value != null)
                {
                    bkn = cellkn.Value.ToString() == "True";

                }

                string gk = "";

                if (bjd)
                {
                    gk += "1";
                }

                if (bzd)
                {
                    gk += "2";
                }

                if (bkn)
                {
                    gk += "3";
                }

                if (!string.IsNullOrEmpty(gk))
                {
                    DataGridViewCell codeCell = row.Cells["code"];
                    if (codeCell != null && codeCell.Value != null)
                    {
                        DataBaseManager.GetInstance.AddChooseChallengeRecord(this.DeviceId, codeCell.Value.ToString(), gk);

                    }
                }


            }

            this.ParentForm.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.ParentForm.Close();
        }
    }
}
